package com.ideal.proxy.impl;

import com.ideal.proxy.TocProxy;
import com.ideal.proxy.entity.TocRequest;
import com.ideal.util.HttpClientUtil;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * <h1> 语雀目录相关接口实现类 </h1>
 *
 * @author ideal-20
 * @date 2023-08-05 00:15
 **/
public class TocProxyImpl implements TocProxy {
    @Override
    public String getTocOfRepo(TocRequest tocRequest) {
        if (tocRequest == null || StringUtils.isBlank(tocRequest.getToken()) || StringUtils.isBlank(tocRequest.getRepoNamespace())) {
            return null;
        }
        String url = tocRequest.getApiUrl() + "/repos/" + tocRequest.getRepoNamespace() + "/toc";
        Map<String, String> headers = new HashMap<>();
        headers.put("User-Agent", tocRequest.getSource());
        headers.put("X-Auth-Token", tocRequest.getToken());
        return HttpClientUtil.doGet(url, null, headers);
    }
}